﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;

namespace TextEditor
{
    public partial class FindDialog : Form
    {
        public TextEditorForm textEditorForm;

        public FindDialog()
        {
            InitializeComponent();
            
        }

        private void buttonGo_Click(object sender, EventArgs e)
        {
            RegexOptions regOps = new RegexOptions();
            if (checkBoxSingleLineMode.Checked)
                regOps |= RegexOptions.Singleline;
            if (checkBoxMuiltiline.Checked)
                regOps |= RegexOptions.Multiline;
            if (checkBoxIgnoreCase.Checked)
                regOps |= RegexOptions.IgnoreCase;
            if (checkBoxRightToLeft.Checked)
                regOps |= RegexOptions.RightToLeft;

            string sReplace = textBoxReplace.Text;
            sReplace = sReplace.Replace("\\n", "\n");
            sReplace = sReplace.Replace("\\r", "\r");
            sReplace = sReplace.Replace("\\0", "\0");
            sReplace = sReplace.Replace("\\t", "\t");

            try
            {
                textEditorForm.setContent(
                    Regex.Replace(textEditorForm.getContent(), textBoxFind.Text, sReplace, regOps)
                    );
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
    
           // s = Regex.Replace(s, ".+\\\\", "", regOps);
        }
    }
}
